# 该模块为汉诺塔游戏的过程动画

import HanoiInitial as hi
import turtle as t

colorX = None


def process(number,a,b,c):

    num = number
    t.speed(2)
    if num == 1:
        moveFrom(num,a)
        moveGoto(num,c)
    else:
        process(num-1,a,c,b)
        moveFrom(num,a)
        moveGoto(num,c)
        process(num-1,b,a,c)


def process2(number,a,b,c):
    hi.initial(number)
    process(number,a,b,c)
    t.done()


def moveFrom(num,columnW):
    global colorX
    print(columnW)
    if len(hi.columnColor[columnW])>0:
        colorX = hi.columnColor[columnW][-1]

    t.goto((-num * 30 / 2) + (columnX(columnW)), (len(hi.columnColor[columnW])-1) * 10 + (-100))
    t.pencolor("white")
    t.pendown()
    t.forward(num * 30 / 2)
    t.pencolor("black")
    t.forward(1)
    t.pencolor("white")
    t.forward(num * 30 / 2 - 1)
    t.penup()
    t.pencolor("black")
    if len(hi.columnColor[columnW])>0:
        hi.columnColor[columnW].pop()

def moveGoto(num,columnW):

    t.goto((-num * 30 / 2) + (columnX(columnW)),(len(hi.columnColor[columnW]))*10+(-100))
    global colorX
    t.pencolor(colorX)
    t.pendown()
    hi.columnColor[columnW].append(t.pencolor())
    t.forward(num * 30)
    t.penup()
    t.pencolor("black")

def columnX(columnW):
    if columnW == 0:
        return -175
    elif columnW == 1:
        return 0
    elif columnW == 2:
        return 175




if __name__ == "__main__":
    # number = int(input("你想生成一个几阶的汉诺塔？"))
    # process函数的第一个参数代表n阶，即圆盘个数
    process2(48,0,1,2)
    print(hi.columnColor)